<?php
defined("_ALLOW") or die ("Access denied");
?>
<script language="javascript">
function checkemail (email) {
	if (email=="") {
		return false;
	}
	if (email.indexOf(" ")>-1) {
		return false;
	}
	if (email.indexOf("@")==-1) {
		return false;
	}
	var i=1;
	var slength=email.length;
	//Neu email la chuoi khong co dau .
	if (email.indexOf(".")==-1) {
		return false;
	}
	//Neu email la chuoi co 2 dau . gan nhau
	if (email.indexOf("..")!=-1) {
		return false;
	}
	//Neu email la chuoi co 2 dau @
	if (email.indexOf("@")!=email.lastIndexOf("@")) {
		return false;
	}
	//Neu email la chuoi co dau . cuoi cung
	if (email.lastIndexOf(".")==email.length-1) {
		return false;
	}
	//Neu email la chuoi co ky tu dau tien la so
	var strso="0123456789";
	if (strso.indexOf(email.charAt(0))!=-1) {
		return 0;
	}
	//Neu email la chuoi co ky tu khong thuoc cac ky tu sau:
	var str="abcdefghijklmnopqrstuvwxyz-@._0123456789";
	for (var j=0; j<email.length; j++) {
		if (str.indexOf(email.charAt(j))==-1) {
			return false;
		}
	}
	return true;
}
function checkregister (form) {
	var email = form.emailregister.value;
	email = trim(email);
	if (!checkemail(email)) {
		alert("Email không hợp lệ");
		form.emailregister.focus();
		return false;
	}
	var password = form.passwordregister.value;
	password = trim(password);
	if (password == "" || password.length<6 ) {
		if (form.addnewregister.value==1) {
			alert("Password có ít nhất là 6 ký tự");
			form.passwordregister.focus();
			return false;
		}
	}
	var password2 = form.password2.value;
	if (password2 != password) {
		form.password2.focus();
		return false;
	}
	var hoten = form.hoten.value;
	hoten = trim(hoten);
	if (hoten=="") {
		alert("Họ tên không được rỗng");
		form.hoten.focus();
		return false;
	}
	return true;
}
</script>
	  <?php
	  	$strrandom = "";
	  	$random = rand(10000,99999);
		$random = md5($random);
		$i=0;
		$randindex = 0;
		for ($i=0; $i<6; $i++) {
			$randindex = rand(0,31);
			$strrandom .= substr($random,$randindex,1);
		}
		$_SESSION['randomregister'] = $strrandom;
	  ?>
<?php
$emailregister = "";
$hotenregister = "";
$dienthoairegister = "";
$diachiregister = "";
$congtyregister = "";
$websiteregister = "";
$addnewregister = 1;
if (isset($_SESSION['username'])) {
	include_once("class/cmkuser.php");
	global $objmkuser;
	$objmkuser = $objmkuser->Doc($_SESSION['username']);
	if ($objmkuser != null) {
		$emailregister = $_SESSION['username'];
		$hotenregister = $objmkuser->hoten;
		$dienthoairegister = $objmkuser->dienthoai;
		$diachiregister = $objmkuser->diachi;
		$congtyregister = $objmkuser->congty;
		$websiteregister = $objmkuser->website;
		$addnewregister = 0;
	}
}
?>
<form id="frmregister" name="frmregister" method="post" action="index.php?module=com_userregister" onSubmit="return checkregister(this)">
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td  align="center">
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
									<tr>
										<td style="background-image:url(images/search1.jpg); background-repeat:no-repeat" width="16" height="35"></td>
										<td style="background-image:url(images/search2.jpg); background-repeat:repeat-x; font-family:Tahoma; font-size:12px; font-weight:bold; text-transform:uppercase; text-align:center; color:#FFFFFF"><?php if ($addnewregister==1) echo "&#272;&#258;NG K&Yacute;"; else echo "C&#7852;P NH&#7852;T"; ?> T&Agrave;I KHO&#7842;N</td>
										<td style="background-image:url(images/search3.jpg); background-repeat:no-repeat" width="15" height="35"></td>
									</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td style="background-image:url(images/search4.jpg); background-repeat:repeat-y; padding-top:10px; padding-bottom:6px; font-family:Tahoma; font-size:11px; font-weight:bold; color:#333333;" >
			
			<table width="80%" border="0" align="center" cellpadding="0" cellspacing="2">
    
    <tr>
      <td width="140">Email</td>
      <td colspan="2" ><input name="emailregister" type="text" id="emailregister" size="50" maxlength="50" onChange="this.value = trim(this.value); " <?php if(isset($_SESSION['username'])) echo "readonly=\"readonly\""; ?> value="<?php echo $emailregister; ?>" />
      <input name="addnewregister" type="hidden" id="addnewregister" value="<?php echo $addnewregister; ?>" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td colspan="2"><input name="passwordregister" type="password" id="passwordregister" size="20" maxlength="20" onChange="this.value = trim(this.value)" /></td>
    </tr>
    <tr>
      <td>Nh&#7853;p l&#7841;i password  </td>
      <td colspan="2"><input name="password2" type="password" id="password2" size="20" maxlength="20" onChange="this.value = trim(this.value)" /></td>
    </tr>
    <tr>
      <td>H&#7885; t&ecirc;n</td>
      <td colspan="2"><input name="hoten" type="text" id="hoten" size="50" maxlength="50" onChange="this.value = trim(this.value)" value="<?php echo $hotenregister; ?>" /></td>
    </tr>
    <tr>
      <td>&#272;i&#7879;n th&#7885;ai</td>
      <td colspan="2"><input name="dienthoai" type="text" id="dienthoai" size="20" maxlength="50" value="<?php echo $dienthoairegister; ?>" /></td>
    </tr>
    <tr>
      <td>&#272;&#7883;a ch&#7881;</td>
      <td colspan="2"><input name="diachi" type="text" id="diachi" size="50" value="<?php echo $diachiregister; ?>" /></td>
    </tr>
    <tr>
      <td>C&ocirc;ng ty</td>
      <td colspan="2"><input name="congty" type="text" id="congty" size="50" value="<?php echo $congtyregister; ?>" /></td>
    </tr>
    <tr>
      <td>Website</td>
      <td colspan="2"><input name="website" type="text" id="website" size="50" maxlength="50" value="<?php echo $websiteregister; ?>" /></td>
    </tr>
    <tr>
      <td>S&#7889; x&aacute;c nh&#7853;n</td>
      <td width="144"><input name="sid" type="text" id="sid" value="" /></td>
      <td width="266"><img src="getimgxacnhan.php" /></td>
    </tr>
    <tr>
      <td> </td>
      <td colspan="2"><input type="submit" name="submit" value="<?php if ($addnewregister==1) echo "&#272;&#259;ng k&yacute;"; else echo "C&#7852;P NH&#7852;T"; ?>" /></td>
    </tr>
  </table>
			
			
			
			</td>
		</tr>
		<tr>
		<td style="background-image:url(images/search5.jpg)" height="9">
		</td>
	</tr>
	</table>
   
</form>